<template>
    <div>
        <!-- 头部 -->
        <!-- <div class="top_tab1">
            <div class="left1" @click="back()">
                <img  src="../assets/order_center/shangs.png">
            </div>
            <span>商家店铺</span>
            <div class="right1">
            </div>
        </div>
        <div class="n"></div> -->
        <div class="neaser" :style="bg">
            <div class="nearbo">
                <div class="nearsearch">
                    <input type="text" name="search" v-model="val"  @keyup.enter="search" placeholder="搜索">
                </div>
            </div>
            <div class="neartab">
                <div class="ntabti">
                    <div>{{shop_name}}</div>
                    <div>&nbsp;</div>
                </div>
                <div class="ntajs">{{category}}</div>
                <div class="nearsc">&nbsp; </div>
            </div>
        </div>
        <div class="nearMain">
            <div class="nearbox" v-for="(item,index) in listList" :key="index">
                <div class="nearbimg">
                    <img :src="item.thumb" alt="">
                </div>
                <div class="nearright">
                    <div class="nrti">{{item.title}}</div>
                    <div class="nrbot">
                      <div>￥{{parseInt(item.mixRMB)}}+{{parseInt(item.mixReds)}}鸿包</div>
                      <div class="heng">
                        <transition name="slide-fade">
                        <div class="jian" v-show="item.number>0"  @click="num(index,'del')">-</div>
                        </transition>
                        <div class="num" v-show="item.number>0" >{{item.number}}</div>
                        <div class="jia" @click="num(index,'add')">+</div>
                      </div>
                    </div>
                </div>
            </div>
        </div>

      <div class="without" v-if="listList.length==0">
          <img src="../assets/order_center/kongbai.png" alt="">
          <span>暂无数据</span>
      </div> 
        <div class="n"></div>
        <div class="nearbottom">
            <div >合计：￥{{cart.price}}+{{cart.hb}}鸿包</div>
            <button type="button" class="jiesuan" @click="account()">去结算</button>
        </div>
        <!-- @click="show = true" -->
        <!-- <yd-popup v-model="show" position="bottom" height="40%" style="z-index:1;">
            <div class="sbottop" @click="show = false">
                <span>清空</span>
                <div>
                    <img src="../assets/product/lajitong.png" alt="">
                </div>
            </div>
            <div class="sholist">
                <div>正步折叠电动车锂电池滑板车代价两轮代步车成人</div>
                <div>
                    <div>￥14.94+9.96鸿包</div>
                    <div v-if="spinner==1" class="botjiajian">
                        <yd-spinner  height="25px" width="25px" button-style="circle" v-model="spinner"></yd-spinner>
                    </div>
                    <div v-else class="botjiajian2">
                        <yd-spinner  height="25px" width="25px" button-style="circle" v-model="spinner"></yd-spinner>
                    </div>
                </div>
            </div>
            <div class="sholist">
                <div>正步折叠电动车锂电池滑板车代价两轮代步车成人</div>
                <div>
                    <div>￥14.94+9.96鸿包</div>
                    <div v-if="spinner==1" class="botjiajian">
                        <yd-spinner  height="25px" width="25px" button-style="circle" v-model="spinner"></yd-spinner>
                    </div>
                    <div v-else class="botjiajian2">
                        <yd-spinner  height="25px" width="25px" button-style="circle" v-model="spinner"></yd-spinner>
                    </div>
                </div>
            </div>
        </yd-popup> -->
    </div>
</template>
<script>
import Vue from "vue";
import { Icons } from "vue-ydui/dist/lib.rem/icons";
Vue.component(Icons.name, Icons);
import { Popup } from "vue-ydui/dist/lib.rem/popup";
Vue.component(Popup.name, Popup);
import { Spinner } from "vue-ydui/dist/lib.rem/spinner";

Vue.component(Spinner.name, Spinner);

export default {
  name: "nearsto",
  data() {
    return {
      show: false,
      spinner: 1,
      id: "",
      val: "",
      listList: [],
      shop_name:'',
      category:'', 
      cart: {
        price: 0,
        hb: 0
      },
      bg:{
            backgroundImage: "url(" + require("../assets/product/diandongchebeijingtu.png") + ")",
            backgroundRepeat: "no-repeat",
      }
    };
  },
  methods: {
    back: function() {
      this.$router.go(-1);
    },
    
    search() {
      this.nearbyShop(this.val);
    },
    nearbyShop(val) {
      let self = this;
      let url = "/api/shop/nearbyShop";
      self.httpPost(
        url,
        {
          user_id: this.myid,
          token: this.token,
          shop_id: this.id,
          text: val,
          pageSize: 999,
          page: 1,
        },
        function(res) {
          if (res.code == 200) {
            // self.listList = res.data.lists;
            self.shop_name = res.data.shop_info.shop_name;
            self.category = res.data.shop_info.category; 
            res.data.lists.forEach((i,e)=>{
               res.data.lists[e].number=0; 
            })
            self.listList = res.data.lists
            console.log( self.listList)
          } else {
            self.$dialog.toast({ mes: res.msg });
          }
        }
      );
    },
     num: function(id, act) {
      //商品加减
      let self = this;
      if(act=='add'){
        self.listList[id].number=self.listList[id].number+1;
      }else if(act=='del')
      {
        self.listList[id].number=self.listList[id].number-1
      } 
      console.log( self.listList) 
      self.calculate()
    },
    calculate: function() {
      //计算价格
      let self = this;
      let price = 0;
      let number = 0;
      self.listList.forEach(e => {
          if (e.number > 0) {
            price += e.number * e.mixRMB;
            number += e.number * e.mixReds;
          }
      });
      self.cart.price = price;
      self.cart.hb = number;
    },
    account: function() {
     //去结算
     if(this.cart.price==0&&this.cart.hb == 0){
        this.$dialog.toast({mes:"请选择商品!"});
        return
     }
      localStorage.setItem("gDCategory", JSON.stringify(this.listList));
      this.$router.push("/account");
    },
  },
  created() {
    document.title = "商家店铺";
    this.token = localStorage.getItem("mytoken");
    this.myid = localStorage.getItem("myid");
    this.id = this.$route.query.ids;
    this.nearbyShop();
  }
};
</script>
<style>
.n {
  height: 0.9rem;
}
.top_tab1 {
  width: 100%;
  padding: 0.2rem 0.3rem;
  background: #fff;
  position: fixed;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.top_tab1 span {
  color: #333;
  font-size: 0.36rem;
  padding-left: 0.8rem;
}
.top_tab1 .right1 {
  width: 1rem;
  display: flex;
  justify-content: space-between;
}
.top_tab1 img {
  width: 0.43rem;
}
.neaser {
  height: 2.95rem;
  padding-top: 0.1rem;
  /* background-image: url("../assets/product/diandongchebeijingtu.png"); */
  background-size: 100%;
}
.nearbo {
  display: flex;
  justify-content: space-around;
}
.nearsearch {
  width: 90%;
  height: 0.88rem;
}
.nearsearch input {
  width: 100%;
  height: 100%;
  border: none;
  text-align: center;
  font-size: 0.35rem;
  background: #fff url(../assets/nearby/sc.png);
  background-repeat: no-repeat;
  border-radius: 0.1rem;
  background-position: 0.1rem center;
  background-size: 0.4rem;
  background-color: #fff;
  
  border: 1px solid #fff;
}
.neartab {
  width: 90%;
  height: 2.1rem;
  padding: 0.3rem 0;
  position: relative;
  background: #fff;
  margin: 0 auto;
  border-radius: 0.3rem;
  bottom: -1rem;
  box-shadow: 0.01rem 0.01rem 0.06rem #ddd;
}
.ntabti {
  width: 90%;
  display: flex;
  justify-content: space-between;
  margin: 0 auto 0.2rem;
  color: #e53636;
}
.ntabti > div:first-child {
  font-size: 0.4rem;
}
.ntabti > div:last-child {
  width: 0.7rem;
  height: 0.45rem;
  font-size: 0.26rem;
  text-align: center;
  line-height: 0.45rem;
  /* border: 1px solid #e53636; */
  border-radius: 0.15rem;
}
.ntajs {
  width: 90%;
  margin: 0 auto;
  font-size: 0.25rem;
  color: #999;
}
.nearsc {
  width: 90%;
  text-align: right;
  color: #999;
  font-size: 0.26rem;
  margin: 0 auto;
}
.nearsc .yd-icon-like:before {
  margin-left: 0.1rem;
  color: #ec5044;
  font-size: 0.3rem;
}
.nearMain {
  /* padding: 0 0 1rem; */
  background: #fff;
  margin-top: 1.2rem;
}
.nearbox {
  width: 90%;
  margin: 0 auto;
  height: 2.2rem;
  display: flex;
  padding: .2rem 0;
  border-bottom: 1px solid #dfdfdf;
}
.nearbimg {
  width: 2.2rem;
  height: 1.8rem;
  border-radius: 0.2rem;
  overflow: hidden;
}
.nearbimg img {
  width: 100%;
  height: 100%;
}
.nearright {
  width: 65%;
  margin-left: 0.3rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.nrti {
  font-size: 0.3rem;
  color: #999;
}
.nrbot {
  display: flex;
  justify-content: space-between;
  color: #e53636;
  font-size: 0.3rem;
}
.nrbot > div:first-child {
  line-height: 1.8rem;
}
.jiah {
  margin-top: 0.25rem;
  width: 0.5rem;
  height: 0.5rem;
  text-align: center;
  line-height: 0.5rem;
  font-size: 0.3rem;
  border-radius: 50%;
  color: #fff;
  background: #e53636;
}
.nearbottom {
  width: 100%;
  position: fixed;
  justify-content: space-between;
  background: #fff;
  bottom: 0;
  height: 1rem;
  border-top: 1px solid #ddd;
  display: flex;
  line-height: 1rem;
  font-size: 0.3rem;
  padding-left: 5%;
  color: #e53636;
  z-index: 8888;
}
.nearbottom > div:first-child {
  width: 70%;
}
.jiesuan {
  width: 30%;
  text-align: center;
  background: #e53636;
  color: #fff;
  border: none;
}
.sbottop {
  height: 0.8rem;
  line-height: 0.8rem;
  border-bottom: 1px solid #ddd;
  padding-right: 5%;
  text-align: right;
  font-size: 0.26rem;
  color: #666;
  display: flex;
  justify-content: flex-end;
}
.sbottop div {
  height: 100%;
  line-height: 0.9rem;
}
.sbottop img {
  margin-left: 0.1rem;
  height: 45%;
}
.sholist {
  height: 1.4rem;
  line-height: 1.4;
  font-size: 0.3rem;
  display: flex;
  border-bottom: 1px solid #ddd;
}
.sholist > div:first-child {
  width: 60%;
  padding: 0 5%;
  margin: auto 0;
  color: #666;
}
.sholist > div:last-child {
  width: 35%;
  padding: 0.2rem 0;
  color: #ed7e7e;
  text-align: right;
}
.botjiajian {
  margin-top: 0.1rem;
}
.botjiajian2 {
  margin-top: 0.1rem;
}
.heng{
  display: flex;
  align-items: center;
  margin-top: -.6rem;
}
.jia{
  width: .45rem;
  height: .45rem;
  text-align: center;
  line-height: .42rem; 
  text-align: center;
  border: 1px solid #ed7e7e;
  background: #ed7e7e;
  color: #fff;
  border-radius: 100%;
}
.num{
  width: .45rem;
  height: .45rem;
  text-align: center;
  line-height: .42rem; 
}
.jian{
  width: .45rem;
  height: .45rem;
  text-align: center;
  line-height: .38rem;
  border-radius: 100%;
  border: 1px solid #ed7e7e;
}
.slide-fade-enter-active {
  transition: all 0.3s ease;
}
.slide-fade-leave-active {
  transition: all 0.8s cubic-bezier(1, 0.5, 0.8, 1);
}
.slide-fade-enter,
.slide-fade-leave-to {
  transform: translateX(30px) rotate(360deg);
  opacity: 0;
}
</style>
<style>
.yd-spinner > input {
  color: #ed7e7e;
}
.yd-spinner-circle > span > i:after {
  top: 45%;
  left: 48%;
}
.botjiajian .yd-spinner > span:last-child > i:after {
  top: 45%;
  left: 48%;
  color: #e84e4e;
}
.botjiajian .yd-spinner-circle > span:last-child {
  background: #f7c5c5;
}
.botjiajian2 .yd-spinner > input {
  color: #ed7e7e;
}
.botjiajian2 .yd-spinner > span > i:after {
  top: 45%;
  left: 48%;
  color: #e84e4e;
}
.botjiajian2 .yd-spinner-circle > span {
  background: #f7c5c5;
}
.yd-mask {
  z-index: 1;
}
/* 无数据 */
.without {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin-top: 0.3rem;
}
.without img {
  width: 3.23rem;
  height: 3.16rem;
}
.without span:nth-child(2) {
  font-size: 0.36rem;
  color: #707070;
  margin-top: 0.43rem;
}
.without span:nth-child(3) {
  font-size: 0.3rem;
  color: #b7b7b7;
  margin-top: 0.3rem;
}
.without .cate {
  color: #fff;
  width: 2.27rem;
  height: 0.8rem;
  line-height: 0.8rem;
  border-radius: 10px;
  font-size: 0.3rem;
  text-align: center;
  background: #e53a30;
  border: none;
  margin-top: 0.96rem;
}
</style>


